package com.jxmcloud.business.cut.service.impl.database;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jxmcloud.business.cut.mapper.database.IUserTurntableLogDBMapper;
import com.jxmcloud.business.cut.model.database.DBUserProgressLog;
import com.jxmcloud.business.cut.model.database.DBUserTurntableLog;
import com.jxmcloud.business.cut.service.database.IUserTurntableLogDBService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class UserTurntableLogDBServiceImpl extends ServiceImpl<IUserTurntableLogDBMapper, DBUserTurntableLog> implements IUserTurntableLogDBService {

    @Override
    public boolean insertData(DBUserTurntableLog dbUserTurntableLog) {
        return this.baseMapper.insert(dbUserTurntableLog) == 1;
    }

    @Override
    public List<DBUserTurntableLog> selectLastN(Integer uid, Integer activityId, Integer n) {
        QueryWrapper<DBUserTurntableLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("uid", uid);
        queryWrapper.eq("activity_id", activityId);
//        queryWrapper.gt("item_id", 0);
//        queryWrapper.gt("item_count", 0);
        queryWrapper.orderByDesc("id");
        queryWrapper.last("LIMIT " + n);
        return this.baseMapper.selectList(queryWrapper);
    }
}
